package meconsea.life.interceptor;

import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import meconsea.life.admin.entity.AdminUser;
import meconsea.life.util.Constant;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class AdminUserSessionInterceptor extends AbstractInterceptor {
	private final static Logger log = Logger.getLogger(AdminUserSessionInterceptor.class);
	
	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		ActionContext ac = invocation.getInvocationContext();
		HttpServletRequest request = (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);
		HttpServletResponse response = (HttpServletResponse) ac.get(ServletActionContext.HTTP_RESPONSE);
		ServletContext servletContext = (ServletContext) ac.get(ServletActionContext.SERVLET_CONTEXT);
		Map session = invocation.getInvocationContext().getSession();
		AdminUser au = (AdminUser)session.get(Constant.ADMIN_USER_SESSION);
		if(au == null){
			return Constant.ADMIN_LOGIN;
		}
		return invocation.invoke();
	}

}
